<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>供应商管理</title>
    <link rel="stylesheet" type="text/css" href="../../static/leftCommon.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/common.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/project.css"/>
</head>
<body>
    <!-- left -->
    <!-- <div class="leftBox"> -->
        <!-- logo -->
        <!-- <p class="logo"><span class="logoImg"></span></p> -->
        <!-- 每一个模块 -->
        <!-- <a class="title clearfix " href="javascript:void(0)" data-permission="c_1">
            <span class="left1"></span>
            <span>物资部业务管理</span> -->
        <!--<span class="direction"></span>-->
        <!-- </a>
        <ul class="personList none" id="project">
            <li data-permission="c_1"><span class=""></span>工作台</li>
            <ul class="threeMenu none">
                <p class="" data-permission="c_1"><a href="workbench.html">工作台</a></p>
            </ul>
            <li data-permission="c_1"><span class=""></span>物资合同审核</li>
            <ul class="threeMenu none">
                <p class="" data-permission="c_1"><a href="contract.html">合同审核</a></p>
                <p class="" data-permission="c_1"><a href="survey.html">供方调查评价</a></p>
                <p class="" data-permission="c_1"><a href="supplier.html">供应商管理</a></p>
            </ul>
        </ul>
    </div> -->
    <div class="rightBox">
         <!-- 搜索区域 -->
        <div class="search">
            <button type="button" class="btnBlue addsupplier none" onclick="window.location.href='supplierdetail.html'">添加供应商</button>
            <select name="" id="status" class="chooseState select">
                <option value="">请选择审核状态</option>
                <option value="0">未审核</option>
                <option value="1">正在审核</option>
                <option value="2">审核通过</option>
                <option value="-1">驳回</option>
            </select>
            <span class="retrieval">检索：</span>
            <input type="text" class="showPhone input" id="condition" style="margin-right: 10px;" placeholder="供方名称">
            <span class="retrieval">供方性质：</span>
            <select name="" id="type" class="select" style="width:14%;margin-right:30px;">
                <option value="">无</option>
                <option value="0">生产厂家</option>
                <option value="1">流通领域</option>
            </select>
            <button type="button" class="btnBlue suprefer">查询</button>
        </div>
        <div class="tableList supTable">
            <table id="list" cellspacing="0" cellpadding="0" style="min-width:1004px;">
                <thead>
                    <tr id="allsup">
                        <th>序号</th>
                        <th>供方名称</th>
                        <th>供方性质</th>
                        <!-- <th>物资类别</th>
                        <th>主要产品</th>
                        <th>联系人/电话</th> -->
                        <th>地址</th>
                        <th>录入时间</th>
                        <th>星级评分</th>
                        <th>评价状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- <tr id="supDetail" class="supDetail" onclick="">
                        <td>1</td>
                        <td id="supplierName" class="supplierName">西安京霸科技有限公司</td>
                        <td>生产厂家</td>
                        <td>消耗品
                        <td>螺纹钢</td>
                        <td>李斌/15101196548</td>
                        <td>唐兴数码</td>
                        <td>2025/11/21</td>
                        <td>未评价</td>
                        <td>
                            <button type="button" style="margin-right:8px;" class="tableBtn pointer" onclick="window.location.href='../survey/joinsurvey.html'">进入评价</button>
                            <button type="button" class="tableBtn pointer" onclick="window.location.href='../contract/conDetail.html'">合同审核</button>
                        </td>
                    </tr> -->
                </tbody>
            </table>
        </div>
            <!-- 分页 -->
        <div class="page1">
            
        </div>
    </div>
</body>
</html>
<script src="../../static/js/jquery-1.8.3.js"></script>
<script src="../../static/dx.js"></script>
<script src="../../static/js/pages.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    DX.ajax_method({
        'type':'GET',
        'url':'/materials/supply/supplierSurvey/showAddBtn',
        'param':{},
        'callBack':function(res){
            if(res.data == true){
                $('.addsupplier').removeClass('none');
            }
        }
    })

    var status = $('#status').val();
    var condition = $('#condition').val();
    var type = $('#type option:selected').val();
    pages.init({
        'key':['status','condition','type'],
        'value':[status,condition,type],
        'url':'/materials/supply/supplier/findMySupplier',
        'callBack':randerList
    })
    
     //初始化页面
    // var page = {'curPage':$('#page_index').val(),'pageSize':$('#page_number').val()};
    // search(page);
	//删除
	// $('.del').click(function(){
	// 	var id = $(this).parents('tr').attr('oid');
	// 	DX.ajax_method({
	// 		'type':'GET',
	// 		'url':'GET /materials/contractAudit/delete',
	// 		'param':{'auid':id},
	// 		'callBack':function(res){
	// 			if(res.code == '200'){
	// 				var obj = pageValue();
	// 				var page = {'curPage':obj.page_pre,'pageSize':obj.page_number};
	// 				search(page);;
	// 			}
	// 		}
	// 	})
	// })
    //查询
    $('.suprefer').click(function(){
        var status = $('#status').val();
        var condition = $('#condition').val();
        var type = $('#type').val();
        pages.init({
            'key':['status','condition','type'],
            'value':[status,condition,type],
            'url':'/materials/supply/supplier/findMySupplier',
            'callBack':randerList
        })
    });

    //点击首页
    // $('.first').click(function(){
    //     $('.pages li').removeClass('page_active');
    //     var obj = pageValue();
    //     if(Number(obj.page_index) < 2){
    //         $('.first').addClass('page_active').siblings().removeClass('page_active');
    //     }
    //     var page = {'curPage':1,'pageSize':obj.page_number};
    //     search(page);
    // });

    //点击上一页
    // $('.pre').click(function(){
    //     $('.pages li').removeClass('page_active');
    //     var obj = pageValue();
		
    //     if(Number(obj.page_index) < 2){
    //         $('.pre').addClass('page_active').siblings().removeClass('page_active');
    //         return false;
    //     }
    //     var page = {'curPage':obj.page_pre,'pageSize':obj.page_number};
    //     search(page);
    // });

    //点击下一页
    // $('.next').click(function(){
    //     $('.pages li').removeClass('page_active');
    //     var obj = pageValue();
    //     if(Number(obj.page_index) >= Number(obj.page_last)){
    //         $('.next').addClass('page_active').siblings().removeClass('page_active');
    //         return false;
    //     }
    //     var page = {'curPage':obj.page_next,'pageSize':obj.page_number};
    //     search(page);
    // });

    //点击尾页
    // $('.last').click(function(){
    //     $('.pages li').removeClass('page_active');
    //     var obj = pageValue();
    //     if(Number(obj.page_index) < 2){
    //         $('.last').addClass('page_active').siblings().removeClass('page_active');
    //     }
    //     var page = {'curPage':obj.page_last,'pageSize':obj.page_number};
    //     search(page);
    // })

    //点击跳转指定页
    // $('#page_tourl').click(function(){
    //     var obj = pageValue();
    //     var toUrl = $('.tourl input').val();
    //     if(Number(obj.page_index) == toUrl) return;
    //     var page = {'curPage':toUrl,'pageSize':obj.page_number};
    //     search(page);
    // })


        // 获取分页value
    // page_index  当前页码
    // page_number 显示数量
    // page_last   共多少页
    // function pageValue(){
    //     var pageIndex = $('#page_index').val();
    //     var pageNumber = $('#page_number').val();
    //     var pageLast = $('#page_last').val();
    //     var pagePre = $('#page_pre').val();
    //     var pageNext = $('#page_next').val();
		
    //     return obj = {
    //         "page_index":pageIndex,
    //         "page_number":pageNumber,
    //         "page_last":pageLast,
    //         "page_pre":pagePre,
    //         "page_next":pageNext
    //     }
		
    // }

    $('#condition').on('keypress',function(e){
        if(e.keyCode == 13){
            $('.suprefer').click();
        }
    })
    $('#status').on('change',function(){
        $('.suprefer').click();
    })
    $('#type').on('change',function(){
        $('.suprefer').click();
    })
    //点击供应商名称出现详情
    $('body').on('click','.supplierName',function(){
        if($(this).parent().parent().next().hasClass('none')){
            $(this).parent().parent().removeClass('bgcolor');
            $(this).parent().parent().next().children().children().stop().slideUp(200,function(){
                $(this).parent().parent().remove();
            });
        }else{
            $(this).parent().parent().addClass('bgcolor')
            var _this = $(this).parent();
            DX.ajax_method({
                'type':'GET',
                'url':'/materials/supply/supplier/findById',
                'param':{id:_this.parent().attr('oid')},
                'change':$(this)[0],
                'callBack':function(res){
                    console.log(res)
                    if(res.code == 200){
                        var html = randerDetail(res.data);
                        _this.parent('tr').after(html);
                        $('#over'+res.data.id).css('width',res.data.starLevel * 20);
                        _this.parent().next().show().children().children().stop().slideUp(0).slideDown(200);
                    }else{
                        alert('服务器异常');
                    }
                }
            })
        }
    })
})




// function search(page){
//     var obj = {
//         status : $('#status').val(),
//         condition : $('#condition').val()
//     };
//     obj = $.extend(obj,page)
//     if(!obj.curPage){obj.curPage = '1'}
//     if(!obj.pageSize){obj.pageSize = '10'}
//     if(obj.curPage < 1){obj.curPage = 1}
//     DX.ajax_method({
//         'type':'GET',
//         'url':'/materials/supplier/findMySupplier',
//         'param':obj,
//         'callBack':function(res){
//             if(res.code == 200){
//                 $('.page_index').html('第'+res.data.pageNum+'页');
//                 $('.page_count').html('总共'+res.data.pages+'页');
//                 $('.page_count1').html('总共'+res.data.total+'条');

//                 $('#page_index').val(res.data.pageNum);
//                 $('#page_last').val(res.data.pages);
//                 $('#page_pre').val(res.data.prePage);
//                 $('#page_next').val(res.data.nextPage);
//                 randerList(res.data);
//             }else{
//                 alert('服务器异常');
//             }
//         }
//     })
// }

var statusMap = {'0':'未评价','1':'评价中','2':'评价通过','-1':'驳回'};
// 创建列表
function randerList(data){
    var data = data.data;
    var html = '';
    for(var i= 0;i < data.list.length;i++){
        var node = data.list[i];
        html += '<tr id="allsupdetail" class="supDetail" oid="' + node.id + '">';
        html += '<td>' + ((data.pageNum - 1) * data.pageSize + i + 1) +'</td>';
        html += '<td id="supplierName">'+'<span class="supplierName listToDetail">'+ node.name +'</span>'+'</td>';
        html += '<td>'+(node.type==0?'生产厂家':'流通领域')+'</td>';
        // html += '<td>'+node.productType+'</td>';
        // html += '<td>'+node.product+'</td>';
        // html += '<td>'+node.liaison+'/'+node.mobile+'</td>';
        html += '<td class="omit">'+node.addressProvince+node.addressSuffix +'</td>';
        html += '<td>'+node.createTime+'</td>';
        html += '<td style="min-width:125px;">'
        html += '<div id="bg" class="lt" style="margin-left:13px;">';       //这里是背景，也就是灰色的星星
        //说明，这里的width就是设置分数啦，以我写的为例，一个星星的长度是12px，也就是1分12px，如果是4.3分，就是4.3*12px = 51.6px的长度，当然这个一般是取得数据后用js或者其他模板语言去控制的
        html += '<div class="overStar" style="width:' + node.starLevel * 20 + 'px;"></div>'   //这里是遮罩，设置宽度以达到评分的效果
        html+='</div>';
        html+='</td>';
        html += '<td>'+statusMap[node.status]+'</td>';
        html+='<td>' + getButton(node.status,node.id) + '</td>';
        // html += '<td>';
        // html += '<button type="button" style="margin-right:8px;" class="tableBtn pointer" onclick="window.location.href=\'../survey/joinsurvey.html\'">进入评价</button>';
        // html += '<button type="button" class="tableBtn pointer" onclick="window.location.href=\'../contract/conDetail.html\'">合同审核</button>';
        // html += '</td>';
        html += '</tr>';
    }
    $('#list tbody').empty().append(html);
    $('#list tbody tr').click(function(){
        DX.clickTr($(this));  
    })

}

function getButton(status,id){
    // if(status == 0){
    //     return '<button class="upandshow" type="button" onclick="joinsurvey(\'' + id + '\')">开始评价</button>';
    // }else{
    //     return '<button class="upandshow" type="button" onclick="isdel(\'' + id + '\')">删除</button>';
    // }
    // return '';
    return '<button class="upandshow listToDetail" type="button" onclick="isdel(\'' + id + '\')">删除</button>';
}


//保存  window.location.href='joinsurvey.html'
function joinsurvey(id){
    window.location.href='../survey/joinsurvey.html?supplierId='+id;
}
function isdel(id){
    var r = confirm('确定删除？');
    if(r){
        DX.ajax_method({
            'type':'POST',
            'url':'/materials/supply/supplier/delete',
            // 'change':$(this)[0],
            'param':{id:id},
            'callBack':function(res){
                window.location.reload();
            }
        })
    }
}
//通过何种认证及证书编号
var approveTypeMap = {1:'质量管理体系认证',2:'安全管理体系认证',3:'环境管理体系认证',4:'职业健康安全管理认证体系'}
//资信等级
var creditLevelMap = {0:"",1:'1A',2:'2A',3:'3A'}
//应急供应能力  1,较强,2:一般,3:较差
var supportAbilityMap = {1:'较强',2:'一般',3:'较差'}
//同类价格比较(1:较高,2:居中,3:较低) ,
var priceCompareMap = {1:'较高',2:'居中',3:'较低'}

//创建的下拉详情渲染
function randerDetail(data){
    var html = '';
    

    var approve = JSON.parse(data.approve);
    var approveHtml='';
    
    $.each(approve,function(i,n){
        approveHtml+=approveTypeMap[n.type]+'：'+n.no+'&emsp;&emsp;';
    })


    html+='<tr class="addsupdet none">';
    html+='<td colspan="8" style="background:none;">';
    html+='<div class="supplierdetail">';
    html+='<ul><li class="mesnav">';
    html+='<span class="supmes pointer">基本信息</span>';
    html+='<span class="suppow pointer">证照、能力</span>';
    html+='<span class="supeva pointer" oid="'+data.id+'">项目部</span>';
    html+='</li><li>';
    html+='<div class="messup">';
    html+='<p class="mesfirrow" style="padding-top: 5px;">';
    html+='<span class="sameSpan">供方名称：</span><span class="samedetail">'+data.name+'</span>';
    html+='<span class="sameSpan">供方性质：</span><span class="samedetail">'+(data.type==0?'生产厂家':'流通领域')+'</span>';
    html+='</p>';
    html+='<p class="messecrow">';
    html+='<span class="sameSpan">公司地址：</span><span class="samedetail omit" style="width:50%;">'+data.addressProvince+data.addressSuffix+'</span>';
    html+='</p>';
    html+='<div style="width：100%;height:35px;">';
    html+='<span class="sameSpan lt">星级评分：</span>'
    html+='<div id="bg" class="lt" style="margin-top:6px;">';       //这里是背景，也就是灰色的星星
    //说明，这里的width就是设置分数啦，以我写的为例，一个星星的长度是12px，也就是1分12px，如果是4.3分，就是4.3*12px = 51.6px的长度，当然这个一般是取得数据后用js或者其他模板语言去控制的
    html+='<div id="over'+data.id+'" class="overStar"></div>'   //这里是遮罩，设置宽度以达到评分的效果
    html+='</div>';
    html+='</div>';
    html+='</div>';
    html+='<div class="powsup none">';
    html+='<p class="powfirrow">';
    html+='<span class="sameSpan">营业执照：</span><span class="samedetail">'+data.businessLicense+'</span>';
    html+='<span class="sameSpan">有效日期：</span><span class="samedetail">'+data.businessExpireDate +'</span>';
    html+='</p>';
    html+='<p class="powsecrow">';
    html+='<span class="sameSpan">许可证号：</span><span class="samedetail">'+data.productLicence+'</span>';
    html+='<span class="sameSpan">有效日期：</span><span class="samedetail">'+data.productExpireDate+'</span>';
    html+='</p>';
    html+='<p class="check" style="heihgt:20px;">';
    html+='<span class="sameSpan">资信等级：</span><span class="samedetail">'+(data.creditLevel?creditLevelMap[data.creditLevel]:'')+'</span>';
    html+='<span class="sameSpan">其他资料：</span><span class="samedetail">'+data.otherInfo+'</span>';
    html+='</p>'
    html+='<p class="powfourow">';
    html+='<span class="sameSpan">认证方式：</span><span style="min-width:121px;line-height: 35px;float: left;">'+approveHtml+'</span>';
    html+='</p>';
    html+='</div>';
    //项目部
    html+='<div class="evasup none" id="sp' + data.id + '">';
    html+='</div>'
    html+='</li>';
    html+='</ul>';
    html+='</div>';
    html+='</td>';
    html+='</tr>';
    return html;
}
 //标签类切换
$('body').on('click','.suppow',function(e){
    $(e.target).css('color','#ffffff').siblings().css('color','black');
    $(e.target).css('background','#0675bc').siblings().css('background','#ffffff');
    $(e.target).parent().next().find('.powsup').css('display','block').siblings().css('display','none');
})
$('body').on('click','.supeva',function(e){
    $(e.target).css('color','#ffffff').siblings().css('color','black');
    $(e.target).css('background','#0675bc').siblings().css('background','#ffffff');
    $(e.target).parent().next().find('.evasup').css('display','block').siblings().css('display','none');
    DX.ajax_method({
        'type':'GET',
        'url':'/materials/supply/supplier/findReference',
        'param':{id:$(e.target).attr('oid'),'pageSize':'10000'},
        'change':$(this)[0],
        'callBack':function(res){
            console.log(res);
            if(res.code == 200){
                showPro(res.data,$(e.target).attr('oid'));
            }
        }   
    })
})
$('body').on('click','.supmes',function(e){
    $(e.target).css('color','#ffffff').siblings().css('color','black');
    $(e.target).css('background','#0675bc').siblings().css('background','#ffffff');
    $(e.target).parent().next().find('.messup').css('display','block').siblings().css('display','none');
})

//项目部回显
function showPro(data,id){
    var html = '';
    for(var i=0;i<data.list.length;i++){
        var node = data.list[i];
        html+='<span class="omit showPro pointer" title="'+node.projectName+'">'+node.abbreviation+'</span>';
    }
    $('#sp' + id).empty().append(html);
}

</script>
<!-- html+='<span class="sameSpan">认证方式：</span><span class="samedetail" style="min-width:121px;">'+(data.approveType?approveTypeMap[data.approveType]:'') +'</span>'; -->